﻿using System.Text.Json;
using System.Text.Json.Serialization;

namespace TXTD.Admin.WebApi.Utilitys.JsonFormat
{
    public class JsonOptionConvert : JsonConverter<DateTime>
    {
        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            string value = reader.GetString();

            DateTime result = DateTime.Parse(value);

            return result;
        }

        public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
        {
            writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
        }
    }
}